<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--
    const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]
    2. 已知数组arr，利用编程以最少的步骤实现以下功能
	a. 获取数组中最大值、最小值
	b. 计算平均值
	c. 求和
	d. 降序排序
	e. 去重
  -->
  <script>
    // a. 获取数组中最大值、最小值
    const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]
    const min = Math.min(...arr)
    console.log(min); //2
    const max =  Math.max(...arr)
    console.log(max); //18

    //  c. 求和  b. 计算平均值
    const total = arr.reduce((prev,current)=>{
        return prev+ current
    },0);
    const average = parseInt((total/arr.length))
    console.log(average);  //7

    // d. 降序排序
    const sort = arr.sort((a,b)=>{
        return b - a
    })
    console.log(sort);
    // [18, 14, 12, 11, 10, 8, 7, 6, 5, 5, 3, 3, 2, 2]

    // e. 去重
    const newArr =  new Set(arr);
     a = Array.from(newArr)
    console.log(a);
    // [18, 14, 12, 11, 10, 8, 7, 6, 5, 3, 2]




       
 







  </script>
</body>
</html>